﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.Web.coffinegurunaru.AppLogic.Page;
using Com.Library.Cookie;
using Com.Library.DB.Board;
using Com.Framework;

namespace Com.Web.coffinegurunaru.whatsnew
{
	public partial class notice_view : WebPage
	{
		public int ArticleSN { get; set;}
		public int PageNo { get; set;}
		public ArticleEntity Entity { get; set;}
		public string SearchWord { get ;set; }
		public string SearchType { get ;set; }

		protected void Page_Load(object sender, EventArgs e)
		{
			ArticleSN = Request["articlesn"].Parse(0);
			PageNo = Request["pageno"].Parse(1);
			SearchWord = Request["searchWord"];
			SearchType = Request["searchType"].Parse("0");

			if (ArticleSN==0)
			{
				ClientScript.RegisterStartupScript(this.GetType(), "articleSNNull", "alert('해당글번호가 없습니다.'); location.href='/whatsnew/notice.aspx?PageNo="+PageNo+"';", true);
				return;
			}
			Entity = ArticleModel.GetInfo(ArticleSN, true, SearchWord);

			if (Entity == null || Entity.n4ArticleSN == 0)
			{
				ClientScript.RegisterStartupScript(this.GetType(), "articleSNNull", "alert('해당글이 없습니다.'); location.href='/whatsnew/notice.aspx?PageNo="+PageNo+"';", true);
				return;
			}

			search.Click += new ImageClickEventHandler(search_Click);
			this.LeftMenuType = 2;
		}

		void search_Click(object sender, ImageClickEventArgs e)
		{
			Response.Redirect("/whatsnew/notice.aspx?searchType=" + searchType.SelectedValue + "&searchWord=" + searchWord.Text);
		}

		public string GetFileName(string fileUrl)
		{
			string[] urlChunks = fileUrl.Split('/');

			return urlChunks[urlChunks.Length-1];
		}

		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);
			searchType.SelectedValue = SearchType;
			searchWord.Text = SearchWord;
		}
		private ManagerCookie m_WebCookie = null;
        public new ManagerCookie WebCookies
        {
            get
            {
                if (m_WebCookie == null)
                {
                    m_WebCookie = new ManagerCookie();
                }

                return m_WebCookie;
            }
        }
	}
}
